/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ConexaoDados;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author erikjan
 */
public class InteracaoDados {
    
  public InteracaoDados()
  {
      
  }
    
    
   public void insereDados(String nome, String host, String no, boolean ativo, int tempo_a, int tempo) throws SQLException
   {
      Connection conexao = ConexaoMySQL.IniciaConexao();
      Statement stm = conexao.createStatement();
      String sql = "INSERT INTO servidoropc(nome, host, no, ativo, tempo_a, tempoTT)   VALUES ('"+nome+"','"+host+"','"+no+"',"+ativo+","+tempo_a+","+tempo+")";
      //System.out.println("SQL :"+sql);  
      stm.executeUpdate(sql);
      stm.close();
    
    }
   public void inserir_unidade(String nomeunidade) throws SQLException
   {
      Connection conexao = ConexaoMySQL.IniciaConexao();
      Statement stm = conexao.createStatement();
      String sql;
      sql = "INSERT INTO unidade (nomeunidade) VALUES ('"+nomeunidade+"')";
      //System.out.println("SQL :"+sql);  
      stm.executeUpdate(sql);
      stm.close();
     
   
   }
   public void inserir_planta(String nomeplanta, int id_unidade) throws SQLException
   {
      Connection conexao = ConexaoMySQL.IniciaConexao();
      Statement stm = conexao.createStatement();
      String sql;
      sql = "INSERT INTO planta (unidade_idUnidade, nomeplanta) VALUES ("+id_unidade+",'"+nomeplanta+"')";
      //System.out.println("SQL :"+sql);  
      stm.executeUpdate(sql);
      stm.close();
   
   }
      public void inserir_equipamento(String nomeequip, int id_planta) throws SQLException
   {
      Connection conexao = ConexaoMySQL.IniciaConexao();
      Statement stm = conexao.createStatement();
      String sql;
      sql = "INSERT INTO equipamento (planta_idplanta, nomeequip) VALUES ("+id_planta+",'"+nomeequip+"')";
       System.out.println("SQL :"+sql);  
      //stm.executeUpdate(sql);
        stm.close();
   
   }
      public ResultSet consulta(String sql) throws SQLException{
      
      Connection conexao = ConexaoMySQL.IniciaConexao();
      Statement stm = conexao.createStatement();
      //System.out.println("SQL :"+sql);  
          
       return stm.executeQuery(sql);
       
      }
      
      public int consulta_item(String sql) throws SQLException{
     
      Connection conexao = ConexaoMySQL.IniciaConexao();
      Statement stm = conexao.createStatement();
      System.out.println("SQL :"+sql); 
      ResultSet rs = stm.executeQuery(sql);
      rs.next();
      return rs.getInt("idUnidade");
       
      }
      
      
      public void deleta(String sql) throws SQLException{
      
      Connection conexao = ConexaoMySQL.IniciaConexao();
      Statement stm = conexao.createStatement();
      stm.executeUpdate(sql);
      
      //System.out.println("SQL :"+sql); 
       stm.close();
         
      }
   
   
    
}
